package com.hxlc.controller;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.alibaba.fastjson.JSONObject;
import com.hxlc.pojo.AgrisResp;
import com.hxlc.pojo.DevicesResp;
import com.hxlc.util.FileReadUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Api(tags = "贵州天镜 卫星小站")
@RestController
@RequestMapping("/api/satellite")
@Slf4j
public class SatelliteAction {
    @Resource
    FileReadUtil fileReadUtil;

    @ApiOperation(value = "获取当前日的数据到报情况")
    @RequestMapping(value = "/getAgrisData", method = RequestMethod.GET)
    private ResponseEntity getAgrisData(@RequestParam String time) {
        log.info("调用接口：{}, 参数：{}", "/tj/api/satellite/getAgrisData", time);
        LocalDateTime dateTime = LocalDateTimeUtil.parse(time, "yyyy-MM-dd HH:mm:ss");
        String string = fileReadUtil.getString("data/getAgrisData.json");
        List<AgrisResp> agrisRespList = JSONObject.parseArray(string, AgrisResp.class);

        return new ResponseEntity(agrisRespList, HttpStatus.OK);

    }

    @ApiOperation(value = "获取设备状态")
    @RequestMapping(value = "/getDeviceData", method = RequestMethod.GET)
    private ResponseEntity getDeviceData() {
        log.info("调用接口：{}, 参数：无", "/tj/api/satellite/getDeviceData");
        String string = fileReadUtil.getString("data/getDevice.json");
        List<DevicesResp> devicesRespList = JSONObject.parseArray(string, DevicesResp.class);
        return new ResponseEntity(devicesRespList, HttpStatus.OK);
    }
}
